<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('账单管理列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

						<li>
						    <label>项目名称：</label>
						    <input type="text" name="projectName"/>
						</li>
                        <li>
                            <label>单位名称：</label>
                            <input type="text" name="companyName"/>
                        </li>
						<li>
						    <label>收费类型：</label>
						    <input type="text" name="chargeType"/>
						</li>
                        <li>
                            <label>开票时间：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="billingBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="billingOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>到账时间：</label>
                            <div class="input-daterange input-group">
                                <input type="text" class="time-input" name="receivedBeginTime" placeholder="请填写日期"/>
                                <span>&nbsp;到&nbsp;</span>
                                <input type="text" class="time-input" name="receivedOverTime" placeholder="请填写日期"/>
                            </div>
                        </li>
                        <li>
                            <label>到账状态：</label>
                            <select name="receivedStatus">
                                <option value="">所有</option>
                                <option value="0">未到账</option>
                                <option value="1">已到账</option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="property:bill:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="property:bill:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="property:bill:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success" onclick="importExcel()" shiro:hasPermission="property:bill:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="property:bill:export">
                <i class="fa fa-download"></i> 导出
            </a>

<!--            <a class="btn btn-success" onclick="openUpload()" shiro:hasPermission="property:tenant:upload">-->
<!--                <i class="fa fa-upload"></i> 上传附件-->
<!--            </a>-->
<!--            <a class="btn btn-warning" onclick="downInfo()" shiro:hasPermission="property:tenant:download">-->
<!--                <i class="fa fa-download"></i> 下载附件-->
<!--            </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('property:bill:edit')}]];
    var removeFlag = [[${@permission.hasPermi('property:bill:remove')}]];
    var prefix = ctx + "sujian/billManagement";
    var options;
    function query() {
        if (options != null && options != undefined) {
            var params = $("#bootstrap-table").bootstrapTable('getOptions');
            $("#bootstrap-table").bootstrapTable('refresh', params);
        } else {
            options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/import",
                importTemplateUrl: prefix + "/importTemplate",
                uniqueId: "billId",
                modalName: "账单管理",
                sortName: "serialNumber",
                sortOrder: "asc",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'serialNumber',
                        title: '序号',
                    },
                    {
                        field: 'billId',
                        title: '租户编号',
                        visible: false
                    },
                    {
                        field: 'projectName',
                        title: '项目名称'
                    },
                    {
                        field: 'companyName',
                        title: '单位名称'
                    },
                    {
                        field: 'chargeType',
                        title: '收费类型'
                    },
                    {
                        field: 'billingTimeConcat',
                        title: '开票时段'
                    },
                    {
                        field: 'billCount',
                        title: '开票金额'
                    },
                    {
                        field: 'billingTime',
                        title: '开票时间'
                    },
                    {
                        field: 'billNumber',
                        title: '发票号'
                    },
                    {
                        field: 'receivedCount',
                        title: '到账金额'
                    },
                    {
                        field: 'receivedTime',
                        title: '到账时间'
                    },
                    {
                        field: 'receivedStatus',
                        title: '状态',
                        formatter: function (value, row, index) {
                            if (row.receivedStatus == "0") {
                                return '<span class="label label-primary">未到账</span>';
                            } else {
                                return '<span class="label label-success">已到账</span>';
                            }
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.billId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.billId + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }
    }


    /**
     * 导出
     * 传递两类参数，默认搜素哦信息，和选中的ids，优先选中ids
     * */
    function exportExcel(){
        var rows=$.table.selectColumns(table.options.uniqueId);
        var msg = "确定导出" + table.options.modalName + "吗？"
        if(rows.length!=0){
            msg = "确定导出勾选的"+rows.length+"条数据吗？"
        }
        $.modal.confirm(msg, function() {
            var params = $("#" + table.options.id).bootstrapTable('getOptions');
            var dataParam = $("#formId").serializeArray();
            dataParam.push({ "name": "orderByColumn", "value": params.sortName });
            dataParam.push({ "name": "isAsc", "value": params.sortOrder });
            if(rows.length!=0){
                dataParam.push({"name": "ids", "value": rows.join()});
            }
            $.modal.loading("正在导出数据，请稍后...");
            $.post(table.options.exportUrl, dataParam, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }
    /**
     * 导入
     * */
    function importExcel(formId, width, height) {
        table.set();
        var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
        var _width = $.common.isEmpty(width) ? "400" : width;
        var _height = $.common.isEmpty(height) ? "230" : height;
        layer.open({
            type: 1,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '导入' + table.options.modalName + '数据',
            content: $('#' + currentId).html(),
            btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
            // 弹层外区域关闭
            shadeClose: true,
            btn1: function(index, layero){
                var file = layero.find('#drfile').val();
                if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
                    $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
                    return false;
                }
                var index = layer.load(2, {shade: false});
                $.modal.disable();
                var formData = new FormData(layero.find('form')[0]);
                $.ajax({
                    url:prefix + "/importExcel",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.closeAll();
                            $.modal.alertSuccess(result.msg);
                            $.table.refresh();
                        } else if (result.code == web_status.WARNING) {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertWarning(result.msg)
                        } else {
                            layer.close(index);
                            $.modal.enable();
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            }
        });
    }

    //
    // /**
    //  * 附件上传
    //  * */
    // function openUpload(){
    //     var rows = $.table.selectColumns("tenantId");
    //     if (rows.length!=1){
    //         $.modal.alertWarning("请选择一条数据进行上传！");
    //         return;
    //     }
    //     var tenantId = rows.join();
    //     $.modal.openTab("上传附件", prefix + "/toUpload/"+tenantId);
    // }
    //
    // function downInfo(){
    //     var rows = $.table.selectColumns("tenantId");
    //     if (rows.length!=1){
    //         $.modal.alertWarning("请选择一条数据进行下载！");
    //         return;
    //     }
    //     var tenantId = rows.join();
    //     $.modal.loading("正在下载请稍后...");
    //     $.post(prefix+"/downloadInfo",{"tenantId":tenantId},function (res) {
    //         if (res.code == web_status.SUCCESS) {
    //             window.location.href = prefix + "/downloadInfo?fileName=" + encodeURI(res.data);
    //         } else if (res.code == web_status.WARNING) {
    //             $.modal.alertWarning(res.msg);
    //         } else {
    //             $.modal.alertError(res.msg);
    //         }
    //         $.modal.closeLoading();
    //     })
    // }



</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="drfile" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果参数已经存在，更新这条数据。"> 是否更新已经存在的参数数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="property:bill:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>

</html>